<?php

Yii::import('common.models.db.AskModel');

class FrontendAskModel extends AskModel
{
	public static function model($className=__CLASS__) {
		return parent::model($className);
	}
	public function getAsks($catid=null, $limit=30, $offset=0, $order='')
	{
		$where = ($catid==null)?"":" AND cat_id = $catid ";
		$order = ($order=='')?" ORDER BY id DESC ":"";
		$sql = "SELECT * FROM tbl_ask WHERE published=1 $where $order LIMIT :offset, :limit";
		$command = Yii::app()->db->createCommand($sql);
		$command->bindParam(':offset', $offset, PDO::PARAM_INT);
		$command->bindParam(':limit', $limit, PDO::PARAM_INT);
		return $command->queryAll();
	}
	public function getTotalAsks($catid=null)
	{
		$where = ($catid==null)?"":" AND cat_id = $catid ";
		$sql = "SELECT count(*) as total FROM tbl_ask WHERE published=1 $where ";
		$command = Yii::app()->db->createCommand($sql);
		$result = $command->queryRow();
		return $result['total'];
	}
}